<!DOCTYPE html>
<!--
Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/base/utils.html">
<link rel="import" href="/tracing/mre/failure.html">

<script>
'use strict';

tr.exportTo('tr.mre', function() {
  function runAndConvertErrorsToFailures(results, job, functionHandle,
      traceHandle, cb, opt_this) {
    try {
      cb.call(opt_this);
    } catch (e) {
      const err = tr.b.normalizeException(e);
      results.addFailure(new tr.mre.Failure(
          job, functionHandle, traceHandle, err.typeName,
          err.message, err.stack));
    }
  }

  return {
    runAndConvertErrorsToFailures
  };
});
</script>
